home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / InputSprocket / Sample Drivers / ISp Sample USB Sources / ISpSampleUSBMain.cp < prev    next >
Encoding:
Text File  |  1998-07-14  |  2.4 KB  |  108 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2.  
  3. File:      ISpSampleUSBMain.cp
  4.  
  5. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  6.  
  7.  
  8. You may incorporate this sample code into your applications without
  9. restriction, though the sample code has been provided "AS IS" and the
  10. responsibility for its operation is 100% yours.  However, what you are
  11. not permitted to do is to redistribute the source as "DSC Sample Code"
  12. after having made changes. If you're going to re-distribute the source,
  13. we require that you make it clear in the source that the code was
  14. descended from Apple Sample Code, but that you've made changes.
  15.  
  16. *************************************************************************************/
  17.  
  18.  
  19. #ifndef __FOLDERS__
  20. #include <Folders.h>
  21. #endif
  22.  
  23. #ifndef __FILES__
  24. #include <Files.h>
  25. #endif
  26.  
  27. #ifndef __CODEFRAGMENTS__
  28. #include <CodeFragments.h>
  29. #endif
  30.  
  31. #ifndef __USB__
  32. #include <USB.h>
  33. #endif
  34.  
  35. #include "ISpSampleUSB.h"
  36. #include "ISpSampleUSBRes.h"
  37.  
  38. #include "dprintf.h"
  39.  
  40.  
  41.  
  42. // type = shlb
  43. // creator = insp
  44.  
  45. #if __MWERKS__
  46. extern "C" __initialize(CFragInitBlockPtr ibp);
  47. extern "C" __terminate(void);
  48. #endif
  49. extern "C" OSErr __myinitialize(CFragInitBlockPtr ibp);
  50. extern "C" void __myterminate(CFragInitBlockPtr ibp);
  51.  
  52. // Initialization routine for when the library is "opened" by an app
  53. OSErr __myinitialize(CFragInitBlockPtr ibp)
  54. {
  55. #if __MWERKS__
  56. OSErr    err = noErr;
  57.     err = __initialize(ibp);
  58.     
  59.     if (err != noErr)
  60.         return err;
  61. #endif
  62.  
  63.     UInt32 inputSprocketVersion = * (UInt32 *) &(ISpGetVersion());
  64.     
  65.     // require InputSprocket 1.1.0
  66.     if (inputSprocketVersion < 0x01100000)
  67.         return noErr;
  68.     
  69.     // if we can't find USBManager, exit gracefully
  70.     if ((Ptr) USBGetNextDeviceByClass == (Ptr) kUnresolvedCFragSymbolAddress)
  71.         return noErr;
  72.     
  73.     // Grab the file spec
  74.     FSSpec fileSpec = {0,0,0};
  75.     if (ibp->fragLocator.where == kDataForkCFragLocator)
  76.     {
  77.         // The shared library should always be located in the data fork
  78.         fileSpec = *ibp->fragLocator.u.onDisk.fileSpec;
  79.     }
  80.     
  81.     ISpUSBDevice::Initialize(fileSpec);
  82.         
  83.     return noErr;    // we don't create an IS device, so IS will unload us
  84. }
  85.  
  86. // Termination routine.  • More TBD here.
  87. void __myterminate(CFragInitBlockPtr ibp)
  88. {
  89. #pragma    unused(ibp)
  90.  
  91.     ISpUSBDevice::Terminate();
  92.  
  93. #if __MWERKS__
  94. __terminate();
  95. #endif
  96. }
  97.  
  98. void *operator new(size_t size)
  99. {
  100.     return NewPtrSys(size);
  101. }
  102.  
  103. void operator delete(void *ptr)
  104. {
  105.     DisposePtr((Ptr) ptr);
  106. }
  107.  
  108.